package web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter("/*")
public class FilterDemo1 implements Filter {
    /**
     * 当Filter创建时执行一次
     *      每一个name配置，都会创建一个新的Filter对象
     *      项目启动时直接创建
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init.....");
    }

    /**
     * 每次拦截到资源时执行，执行多次
     * @param request
     * @param response
     * @param chain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("filterdemo1 run ....");
    }

    /**
     * 销毁时执行，执行一次
     */
    @Override
    public void destroy() {
        System.out.println("destroy....");
    }
}
